@extends('admin.master')

@section('style')
<link rel="stylesheet" href="{{ url('css/bootstrap-datetimepicker.css') }}">
<link rel="stylesheet" href="{{ url('js/prettyphoto/css/prettyPhoto.css') }}">
@endsection

@section('top')
<div class="top-breadcrumb pull-left">{!! Breadcrumbs::render('order-show', $data, $u) !!}</div>
@endsection

@section('content')
<div class="alert alert-warning remark-show" role="alert">
    @if ($data->remark)
        {!! nl2br($data->remark) !!}
    @else
        <div class="no-text"><i class="fa fa-exclamation-circle" aria-hidden="true"></i> <span>暂无任何备注信息！</span></div>
    @endif
</div>
<div class="partition"><span>订单详情</span></div>
<table class="table table-bordered">
    <thead>
        <tr>
            <th class="text-center">套餐</th>
            <th class="text-center">年限</th>
            <th>订单类型</th>
            <th class="text-center text-success"><strong>进度</strong></th>
            <th>签单日期</th>
            <th>上线日期</th>
            <th>到期日期</th>
            <th>签单金额</th>
            <th>关键词</th>
            <th>参考网站</th>
            <th>架构编号</th>
            <th>临时网址</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="text-center">
                @if ($data->web_package)
                    {{ config('system.web_package')[$data->web_package] }}
                @endif
            </td>
            <td class="text-center">
                <strong><span class="text-warning text-size-14">{{ $data->year }} 年</span></strong>
            </td>
            <td>{{ isset(config('system')['product'][$data->type][$data->product]) ? config('system')['product'][$data->type][$data->product] : '' }}</td>
            <td class="text-center"><span class="text-success"><strong>{{ config('system')['order_status'][$data->status] }}</strong></span></td>
            <td>{{ $data->signed_at->format('Y-m-d') }}</td>
            <td>{{ $data->finished_at->toDateTimeString() > 0 ? $data->finished_at->format('Y-m-d') : null }}</td>
            <td><span class="text-danger">{{ $data->expired_at->format('Y-m-d') }}</span></td>
            <td>{{ $data->amount }} <span class="label label-warning show-tail-amount">尾款：{{ $data->tail_amount }}</span></td>
            <td>{{ $data->keywords }}</td>
            <td>{{ $data->reference_site }}</td> 
            <td>{{ $data->web_number }}</td>       
            <td><a href="http://{{ $data->temp_url }}" target="_blank">{{ $data->temp_url }}</a></td>
        </tr>
    </tbody>
</table>
@if (!$data->renews->isEmpty()) 
<div class="partition"><span>续费情况</span></div>
<table class="table table-bordered">
    <thead>
        <tr>
            <th>续费时间</th>
            <th>年限</th>
            <th>业务员</th>
            <th>续费金额</th>
            <th>合同号</th>
            <th>合同图片</th>
            <th>发票类型</th>
            <th>发票回执</th>
            <th>发票状态</th>
            <th>回执状态</th>
            <th>备注</th>
        </tr>
    </thead>
    <tbody>
        @foreach($data->renews as $renew)
        <tr>
            <td>{{ $renew->created_at->format('Y-m-d') }}</td>
            <td>{{ $renew->year }}</td>
            <td>{{ $renew->saler->name }}</td>
            <td>{{ $renew->amount }}</td>
            <td><code>{{ $renew->contract->contract_no }}</code></td>
            <td>
            @if ($renew->contract->contract && is_array($renew->contract->contract))
                <ul class="contract-imgs">
                    @foreach($renew->contract->contract as $contract)
                    <li>
                        <a href="{{ url($contract) }}" class="thumbnail" rel="prettyPhoto[contracts-renew]">
                            <img src="{{ thumbFull($contract, 80) }}">
                        </a>
                    </li>
                    @endforeach
                </ul>
            @endif
            </td>
            <td>{{ config('system.invoice_type')[$renew->contract->invoice_type] }}</td>
            <td>
            @if ($renew->contract->invoice_receipt && is_array($renew->contract->invoice_receipt))
                <ul class="contract-imgs">
                    @foreach($renew->contract->invoice_receipt as $receipt)
                    <li>
                        <a href="{{ url($receipt) }}" class="thumbnail" rel="prettyPhoto[receipts-renew]">
                            <img src="{{ thumbFull($receipt, 80) }}">
                        </a>
                    </li>
                    @endforeach
                </ul>
            @endif 
            </td>
            <td>
                @if($renew->contract->invoice_status == 1)
                    <span class="label label-success">发票已开</span>
                @endif
            </td>
            <td>
                @if($renew->contract->invoice_receipt_status == 1)
                    <span class="label label-success">回执已收</span>
                @endif
            </td>
            <td></td>
        </tr>
        @endforeach
    </tbody>
</table>
@endif
<div class="partition"><span>客户概况</span></div>
<table class="table table-bordered">
    <thead>
        <tr>
            <th>客户名称</th>
            <th>联系人</th>
            <th>手机号</th>
            <th>座机</th>
            <th>传真</th>
            <th>域名</th>
            <th>区域</th>
            <th>详细地址</th>
        </tr>
    </thead>
    <tbody>
        <tr>          
            <td>{{ $data->customer->name }}</td>
            <td>{{ $data->contact_people }}</td>
            <td>{{ $data->phone }}</td>
            <td>{{ $data->tel }}</td>
            <td>{{ $data->fax }}</td>
            <td><a href="http://{{ $data->domain }}" target="_blank">{{ $data->domain }}</a></td>
            <td>{{ $data->city->implode(' ') }}</td>
            <td>{{ $data->detail_address }}</td>
        </tr>
    </tbody>
</table>
@if ($data->type == 1)
<div class="partition"><span>生产进度</span></div>
<div class="language-wrap pt10">
  <ul>
  @foreach($data->lan as $key=>$value)
    <li class="clearfix">
      <div class="col-md-1 lan-name">{{ config('system.language')[$value->language] }}：</div>
      <div class="col-md-6">
        <div class="progress">
          <div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" style="width: {{ intval($value->progress/5*100) }}%">
            <span>{{ $value->progress == 0 ? '' : config('system.lan_progress')[$value->progress] }}</span>
          </div>
        </div>
      </div>
    </li>
  @endforeach
  </ul>
</div>
@endif
@if ($data->contract)
<div id="contract-show" class="mt-15">
    <div class="partition"><span>合同和发票</span></div>
    <table class="table">
        <thead>
            <tr>
                <th>合同号</th>
                <th>发票类型</th>
                <th>合同图片</th>
                <th>发票回执</th>
                <th>发票状态</th>
                <th>回执状态</th>
                <th>备注</th>
            </tr>
        </thead>
        <tbody>
            <td><code>{{ $data->contract->contract_no }}</code></td>
             <td>{{ config('system.invoice_type')[$data->contract->invoice_type] }}</td>
            <td>
            @if ($data->contract->contract && is_array($data->contract->contract))
                <ul class="contract-imgs">
                    @foreach($data->contract->contract as $contract)
                    <li>
                        <a href="{{ url($contract) }}" class="thumbnail" rel="prettyPhoto[contracts]">
                            <img src="{{ thumbFull($contract, 80) }}">
                        </a>
                    </li>
                    @endforeach
                </ul>
            @endif
            </td>
            <td>
            @if ($data->contract->invoice_receipt && is_array($data->contract->invoice_receipt))
                <ul class="contract-imgs">
                    @foreach($data->contract->invoice_receipt as $receipt)
                    <li>
                        <a href="{{ url($receipt) }}" class="thumbnail" rel="prettyPhoto[receipts]">
                            <img src="{{ thumbFull($receipt, 80) }}">
                        </a>
                    </li>
                    @endforeach
                </ul>
            @endif
            </td>
            <td>
                @if($data->contract->invoice_status == 1)
                    <span class="label label-success">发票已开</span>
                @endif
            </td>
            <td>
                @if($data->contract->invoice_receipt_status == 1)
                    <span class="label label-success">回执已收</span>
                @endif
            </td>
            <td>{{ $data->contract->remark }}</td>
        </tbody>
    </table>
</div>
@endif
<div class="partition"><span>用户信息</span></div>
<table class="table">
    <thead>
        <tr>
            <th class="text-center">业务员</th>
            <th class="text-center">设计师</th>
            <th class="text-center">程序员</th>
            <th class="text-center">录入员</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="text-center">
                @if ($data->saler)
                    <div class="order-show-saler">
                        <span>{{ $data->saler->region->name or '---' }}</span>
                        <span>{{ $data->saler->department->name or '---' }}</span>
                        <span class="text-size-14"><code>{{ $data->saler->name or '---' }}</code></span> 
                    </div>
                @else
                    <span>---</span>
                @endif
            </td>
            <td class="text-center">{{ $data->designer->name or '---' }}</td>
            <td class="text-center">{{ $data->programmer->name or '---' }}</td>
            <td class="text-center">{{ $data->inputer->name or '---' }}</td>
        </tr>
    </tbody>
</table>
@if ($data->status == 3 && $data->webPermission)
<div class="partition"><span>登录权限</span></div>
<ul class="web-permission-show">
@if(in_array($user->group->level, [5, 6, 10]))
    <li>
        <span class="login-user">用户名：<code class="text-size-14">{{ $data->webPermission->super_user['username'] }}</code></span>
        <span class="login-user">密码：<code class="text-size-14">{{ $data->webPermission->super_user['password'] }}</code></span>
    </li>
    <li>
        <span class="login-user">用户名：<code class="text-size-14">{{ $data->webPermission->admin_user['username'] }}</code></span>
        <span class="login-user">密码：<code class="text-size-14">{{ $data->webPermission->admin_user['password'] }}</code></span>
    </li>
@else
    <li>
        <span class="login-user">用户名：<code class="text-size-14">{{ $data->webPermission->admin_user['username'] }}</code></span>
        <span class="login-user">密码：<code class="text-size-14">{{ $data->webPermission->admin_user['password'] }}</code></span>
    </li>
@endif
</ul>
@endif
<div class="partition mb15">
    <div class="total"><span>留言数量：{{ $data->replies->count() }}</span></div>
</div>
<div class="panel-body reply-list-box">
@if (!$data->replies->isEmpty())
    <ul class="list-group">
    <?php $i=1; ?>
    @foreach ($data->replies as $reply)
    <li class="list-group-item clearfix">
        <div class="avatar pull-left mr10">
            <a class="avatar-thumb">{{ $reply->user->name }}</a>
        </div>
        <div class="infos">
            <div class="info mb5">
                <span class="name"><b>{{ $reply->user->username }}</b></span>
                <span class="dot"> •</span>
                <span class="floor text-success">#{{ $i++ }}</span>
                <span class="dot"> •</span>
                <abbr class="timeago">{{ $reply->created_at }}</abbr>
            </div>
            <div class="reply-content">
                {!! $reply->content !!}
            </div>
        </div>
    </li>
    @endforeach
    </ul>
@else 
    <div class="empty-block">暂无留言~~</div>
@endif
</div>
<div class="reply-box">
{!! Form::open(['route' => 'admin.reply.store', 'class'=>'form-horizontal', 'id'=>'reply-form']) !!}
    {!! Form::hidden('order_id', $data->id) !!}
    <div class="form-group">
        <script id="editor" name="content" type="text/plain"></script>
    </div>
    <div class="form-group">
    	<input type="submit" class="btn btn-primary" id="reply-submit" value="发表留言">
    </div>
{!! Form::close() !!}
</div>
@endsection

@section('foot')
<script src="{{ url('js/bootstrap.min.js') }}"></script>
<script src="{{ url('js/ueditor/ueditor.config.js') }}"></script>
<script src="{{ url('js/ueditor/ueditor.all.min.js') }}"></script>
<script src="//cdn.bootcss.com/moment.js/2.10.6/moment.min.js"></script>
<script src="//cdn.bootcss.com/moment.js/2.10.6/locale/zh-cn.js"></script>
<script src="{{ url('js/prettyphoto/jquery.prettyPhoto.js') }}"></script>
<script>

 var ue = UE.getEditor('editor');

$(function() {
    $("a[rel^='prettyPhoto']").prettyPhoto({social_tools: ''});
});
	
// 发表时间格式化
$('.timeago').each(function() {
	var t = $(this).text();
	moment(t,"YYYY-MM-DD HH:mm:ss", true).isValid() && $(this).text(moment(t).fromNow());
});

// 是链接弹出新页面
$('.reply-content a').each(function() {
	$(this).attr('target', '_blank');
});

$('.renew-detail').on('click', function() {
    $('#dialog-renew').modal('show');
});

$('.contract-open').on('click', function(e) {
    e.preventDefault();
    var width = 600;
    var height = 450;
    var top  = (window.screen.availHeight - height) / 2;
    var left = (window.screen.availWidth-10-width) / 2
    window.open(this.href, "_blank" ,"width="+width+",height="+height+",top="+top+",left="+left+"toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
    return false;
});

</script>
@endsection
